package cn.slipi.pan.web.mapper;

import cn.slipi.pan.web.entity.VersionEntity;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;
import java.util.Set;

/**
 * mapper
 */
@Mapper
public interface VersionMapper extends BaseMapper<VersionEntity> {

    default List<VersionEntity> listAll() {
        return this.selectList(new LambdaQueryWrapper<>());
    }

    default VersionEntity queryById(Integer id) {
        return this.selectOne(new LambdaQueryWrapper<VersionEntity>().eq(VersionEntity::getId, id));
    }

    default VersionEntity queryLeast() {
        LambdaQueryWrapper<VersionEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.orderByDesc(VersionEntity::getCreateTime);
        lambdaQueryWrapper.last("LIMIT 1");
        return this.selectOne(lambdaQueryWrapper);
    }

    default List<VersionEntity> findByIds(Set<Integer> ids) {
        return selectBatchIds(ids);
    }
}
